package openrr.geom;

import java.util.ArrayList;


//the Mesh class is a collection of TextureGroups, that could be seen as a "model" on the stage.
//I haven't expanded this part too much; but it would be possible to make it into a tree structure where a mesh can contain other meshes that are transformed relative to the mesh they are in (using glPushMatrix() etc).
public class Mesh {
	//the list of texture groups that the mesh contains
	private ArrayList<TextureGroup> renderList;
	private ArrayList<Mesh>childs;
	
	//the constructor
	public Mesh()
	{
		this.renderList = new ArrayList<TextureGroup>();
		this.childs = new ArrayList<Mesh>();
	}
	//adds a texture group to the mesh
	public void addGroup(TextureGroup group)
	{
		this.renderList.add(group);
	}
	//remders each of the texture groups in the mesh
	public void render()
	{
		for(int i = 0; i < this.renderList.size(); i++)
		{
			this.renderList.get(i).draw();
		}
		for(int i = 0; i < this.childs.size(); i++)
		{
			this.childs.get(i).render();
		}
	}
	
	public void addChild(Mesh child)
	{
		this.childs.add(child);
	}
	//resets the texture group list, so that it can be filled with new geometry data
	//the java garbage collector should deal with cleaning up the old contents, as this is the only place the groups are referenced.
	public void clear()
	{
		this.renderList = new ArrayList<TextureGroup>();
	}
}